package demo4;

public class Computer {
    public void powerOn() {
        System.out.println("打开笔记本电脑");
    }
    public void powerOff() {
        System.out.println("关闭笔记本电脑");
    }
    public void useDevice(IUSB iusb) {
        iusb.openDevice();
        if (iusb instanceof Mouse) {
            Mouse mouse = (Mouse) iusb;
            mouse.click();
        } else if (iusb instanceof keyBoard) {
            keyBoard keyBoard = (demo4.keyBoard) iusb;
            keyBoard.inPut();
        }
        iusb.closeDevice();
    }

    public static void main(String[] args) {
        Computer computer = new Computer();
        computer.powerOn();//打开电脑

        computer.useDevice(new Mouse());//鼠标
        computer.useDevice(new keyBoard());//键盘

        computer.powerOff();//关闭电脑
    }
}
